#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,C=10,inf=1e16;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
bool SSS;

int n,m,q,c[N],a[N][C],sum[N][C],lstans;

struct Seg{
	int t[N<<2],laz[N<<2];
	
	#define ls (x<<1)
	#define rs (x<<1|1)
	#define mid (l+r>>1)
	
	void pushup(int x){
		t[x]=max(t[ls],t[rs]);
	}
	void down(int x,int k){
		t[x]+=k,laz[x]+=k;
	}
	void pushdown(int x){
		if(laz[x]==0) return;
		down(ls,laz[x]);
		down(rs,laz[x]);
		laz[x]=0;
	}
	void build(int x,int l,int r){
		t[x]=-inf,laz[x]=0;
		if(l==r) return;
		build(ls,l,mid);
		build(rs,mid+1,r);
	}
	void update(int x,int l,int r,int L,int R,int k){
		if(l>=L&&r<=R){
			down(x,k);
			return;
		}
		pushdown(x);
		if(L<=mid) update(ls,l,mid,L,R,k);
		if(R>mid) update(rs,mid+1,r,L,R,k);
		pushup(x);
	}
	void modify(int x,int l,int r,int p,int k){
		if(l==r){
			t[x]=k;
			return;
		}
		pushdown(x);
		if(p<=mid) modify(ls,l,mid,p,k);
		else modify(rs,mid+1,r,p,k);
		pushup(x);
	}
	int query(int x,int l,int r,int L,int R){
		if(l>=L&&r<=R) return t[x];
		pushdown(x);
		int res=-inf;
		if(L<=mid) res=max(res,query(ls,l,mid,L,R));
		if(R>mid) res=max(res,query(rs,mid+1,r,L,R));
		return res;
	}

	#undef ls
	#undef rs
	#undef mid
}S[C];

int f[N];
void solve(int l,int r){
	for(int i=1;i<=m;i++) S[i].build(1,1,n);
	f[l-1]=0;
	for(int i=l;i<=r;i++){
		f[i]=f[i-1]+a[i][c[i]];
		S[c[i]].modify(1,1,n,i,f[i-1]);
		for(int j=1;j<=m;j++) S[j].update(1,1,n,l,i,a[i][j]);
		f[i]=max(f[i],S[c[i]].query(1,1,n,l,i));
	}
	lstans=f[r];
}

struct Node{
	int ans,s[C];
	int pre[C],suf[C],pos_pre[C],pos_suf[C];
	void clear(){
		ans=-inf;
		for(int i=1;i<=m;i++) pre[i]=suf[i]=-inf,s[i]=0,pos_pre[i]=pos_suf[i]=0;
	}
};

int tp;
pair<int,int> s1[N],s2[N];

struct SEG{
	Node t[N<<2];
	
	#define ls (x<<1)
	#define rs (x<<1|1)
	#define mid (l+r>>1)
	
	Node merge(Node a,Node b){
		Node c;c.clear();
		c.ans=a.ans+b.ans;
		tp=0;
		for(int i=1;i<=m;i++){
			if(b.pre[i]+a.s[i]>a.pre[i]+b.ans) c.pos_pre[i]=b.pos_pre[i];
			else c.pos_pre[i]=a.pos_pre[i];
			c.pre[i]=max(b.pre[i]+a.s[i],a.pre[i]+b.ans);
			
			if(a.suf[i]+b.s[i]>b.suf[i]+a.ans) c.pos_suf[i]=a.pos_suf[i];
			else c.pos_suf[i]=b.pos_suf[i];
			c.suf[i]=max(a.suf[i]+b.s[i],b.suf[i]+a.ans);

			c.ans=max(c.ans,a.suf[i]+b.pre[i]);

			++tp;
			s1[tp]={(a.suf[i]+b.pre[i]-a.ans-b.ans)>0?(a.suf[i]+b.pre[i]-a.ans-b.ans):0,a.pos_suf[i]};
			s2[tp]={(a.suf[i]+b.pre[i]-a.ans-b.ans)>0?(a.suf[i]+b.pre[i]-a.ans-b.ans):0,b.pos_pre[i]?b.pos_pre[i]:inf};

			c.s[i]=a.s[i]+b.s[i];
		}
		for(int i=1;i<=m;i++){
			int mx1=0,mx2=0;
			for(int j=1;j<=tp;j++){
				if(a.pos_pre[i]<s1[j].second) mx1=max(mx1,s1[j].first);
				if(b.pos_suf[i]>s2[j].second) mx2=max(mx2,s2[j].first);
			}
			a.pre[i]+=mx1,b.suf[i]+=mx2;
		}
		for(int i=1;i<=m;i++){
			if(b.pre[i]+a.s[i]>a.pre[i]+b.ans) c.pos_pre[i]=b.pos_pre[i];
			else c.pos_pre[i]=a.pos_pre[i];
			c.pre[i]=max(b.pre[i]+a.s[i],a.pre[i]+b.ans);
			
			if(a.suf[i]+b.s[i]>b.suf[i]+a.ans) c.pos_suf[i]=a.pos_suf[i];
			else c.pos_suf[i]=b.pos_suf[i];
			c.suf[i]=max(a.suf[i]+b.s[i],b.suf[i]+a.ans);
		}
		return c;
	}
	void pushup(int x){
		t[x]=merge(t[ls],t[rs]);
	}
	void build(int x,int l,int r){
		t[x].clear();
		if(l==r){
			t[x].pre[c[l]]=t[x].suf[c[l]]=a[l][c[l]];
			t[x].pos_pre[c[l]]=t[x].pos_suf[c[l]]=l;
			for(int i=1;i<=m;i++) t[x].s[i]=a[l][i];
			t[x].ans=a[l][c[l]];
			return;
		}
		build(ls,l,mid);
		build(rs,mid+1,r);
		pushup(x);
	}
	void modify(int x,int l,int r,int p,int k){
		if(l==r){
			t[x].clear(),c[l]=k;
			t[x].pre[c[l]]=t[x].suf[c[l]]=a[l][c[l]];
			t[x].pos_pre[c[l]]=t[x].pos_suf[c[l]]=l;
			for(int i=1;i<=m;i++) t[x].s[i]=a[l][i];
			t[x].ans=a[l][c[l]];
			return;
		}
		if(p<=mid) modify(ls,l,mid,p,k);
		else modify(rs,mid+1,r,p,k);
		pushup(x);
	}
	Node query(int x,int l,int r,int L,int R){
		if(l>=L&&r<=R) return t[x];
		if(L>mid) return query(rs,mid+1,r,L,R);
		if(R<=mid) return query(ls,l,mid,L,R);
		return merge(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));
	}
	
	#undef ls
	#undef rs
	#undef mid
}T;

bool TTT;
signed main(){
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	n=read(),m=read(),q=read();
	for(int i=1;i<=n;i++) c[i]=read();
	int sm=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			a[i][j]=read();
			sum[i][j]=sum[i-1][j]+a[i][j];
		}
		sm+=a[i][c[i]];
	}
	if(n<=8||q==0){
		solve(1,n);
		printf("%lld\n",lstans);
		int opt,x,y;
		while(q--){
			opt=read(),x=read(),y=read();
			x^=lstans,y^=lstans;
			if(opt==1){
				c[x]=y;
			}
			else{
				solve(x,y);
				printf("%lld\n",lstans);
			}
		}		
	}
	else{
		T.build(1,1,n);
		lstans=T.t[1].ans;
		printf("%lld\n",lstans);
		int opt,x,y;
		while(q--){
			opt=read(),x=read(),y=read();
			x^=lstans,y^=lstans;
			if(opt==1) T.modify(1,1,n,x,y);
			else{
				lstans=T.query(1,1,n,x,y).ans;
				printf("%lld\n",lstans);
			}
		}			
	}
	return 0;
}